package cn.yunhe.server;

import cn.yunhe.dao.IAdminDao;
import cn.yunhe.entity.Admin;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminServer {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession();
    IAdminDao adminDao = session.getMapper(IAdminDao.class);

    /**
     * 登录验证,若登录的账号密码存在则返回一个完整的用户对象
     * @param admin
     * @return
     */
    public Admin Login(Admin admin){
        return adminDao.Login(admin);
    }

    /**
     * 获取所有管理员对象
     * @return
     */
    public List<Admin>  getAllAdmin(){
        return adminDao.getAllAdmin();
    }

    /**
     * 用户注册
     * @param username
     * @param password
     * @return
     */
    public boolean register(String username,String password){
        Admin admin = new Admin(username, password);
        boolean flag = adminDao.register(admin);
       if (flag){
           session.commit();
           return true;
       }else {
           return false;
       }
    }
}
